<?php

namespace App\Exports\Pay\Elasticsearch;

use App\Exports\Pay\WalletExport as Export;

class WalletExport extends Export
{

    /**
     * 映射数据行
     *
     * @param array $item
     * @return array
     */
    protected function map($item): array
    {
        $item = $item['_source'];

        return [
            $item['sn'],
            $item['uid'],
            $this->orgs[$item['plat_code']]['name'] ?? $item['plat_code'],
            $item['account_id'],
            $this->paymentList[$item['payment']] ?? $item['payment'],
            empty($item['consume']) ? null : json_encode($item['consume']),
            empty($item['take_back']) ? null : json_encode($item['take_back']),
            $this->statusList[$item['status']] ?? $item['status'],
            timestamp_to_datetime($item['created']),
            timestamp_to_datetime($item['updated']),
            !isset($item['usd']['consume']) ? null : json_encode($item['usd']['consume']),
            !isset($item['usd']['take_back']) ? null : json_encode($item['usd']['take_back']),
        ];
    }

    /**
     * 初始化操作
     */
    protected function init()
    {
        parent::init();

        // 初始化平台列表
        $this->initOrgs();
    }
}
